﻿<UserControl x:Class="Adan.Client.Common.Controls.ActionParametersEditorControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Expander IsExpanded="True" HorizontalAlignment="Stretch">
            <Expander.Header>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column="0" TextTrimming="WordEllipsis">Parameters:</TextBlock>
                    <TextBlock Grid.Column="1" Margin="5,0,0,0"  TextTrimming="CharacterEllipsis" Text="{Binding Path=ActionParametersDescription,Mode=OneWay}"/>
                    <Button Grid.Column="2" Width="18" Height="18" HorizontalAlignment="Right" Margin="0,0,5,0" Command="{Binding Path=AddParameterCommand}"  Visibility="{Binding Path=ParametersCollectionEmpty, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}">
                        <ContentControl Style="{StaticResource AddItemIcon}" Width="10" Height="10"/>
                    </Button>
                </Grid>
            </Expander.Header>
            <ItemsControl ItemsSource="{Binding Path=Parameters}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Border Margin="2" Padding="2" BorderBrush="Black" BorderThickness="1"  CornerRadius="2,2,2,2">
                            <StackPanel>
                                <Grid HorizontalAlignment="Right">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <ComboBox Grid.Column="0" Width="200" SelectedValue="{Binding Path=ParameterDescriptor}" ItemsSource="{Binding AllParameterDescriptions}" DisplayMemberPath="DisplayName" />
                                    <Button Grid.Column="1" Width="22" Height="22" Command="{Binding Path=DataContext.AddParameterCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}}" CommandParameter="{Binding}">
                                        <ContentControl Style="{StaticResource AddItemIcon}" Width="14" Height="14"/>
                                    </Button>
                                    <Button Grid.Column="2" Width="22" Height="22" Command="{Binding Path=DataContext.DeleteParameterCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}}" CommandParameter="{Binding}">
                                        <ContentControl Style="{StaticResource DeleteIcon}" Width="14" Height="14"/>
                                    </Button>
                                    <Button Grid.Column="3" Width="22" Height="22" Command="{Binding Path=DataContext.MoveParameterUpCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}}" CommandParameter="{Binding}">
                                        <ContentControl Style="{StaticResource UpIcon}" Width="14" Height="14"/>
                                    </Button>
                                    <Button Grid.Column="4" Width="22" Height="22" Command="{Binding Path=DataContext.MoveParameterDownCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}}" CommandParameter="{Binding}">
                                        <ContentControl Style="{StaticResource DownIcon}" Width="14" Height="14"/>
                                    </Button>
                                </Grid>
                                <ContentPresenter Margin="2,0,2,2" ContentTemplateSelector="{Binding Source={StaticResource GenericTemplateSelector}}" DataContext="{Binding}" />
                            </StackPanel>
                        </Border>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Expander>
    </Grid>
</UserControl>
